<!-- 冈好办 -->
<template>
    <div class="container">
            <div class="card">
                <div class="card-header">
                    <div class="card-title">
                        <img src="../../assets/img/line.png" alt />
                        <span>政策文件</span>
                    </div>
                    <div class="card-more" @click="toPage('pages/gangEasyMake/policyMore')">
                        <span style="margin-right: 3px; color: #0c92ff;">查看更多</span>
                        <u-icon color="#0c92ff" name="arrow-right"></u-icon>
                    </div>
                </div>
                <div v-if="gangPolicyList.length" class="card-list">
                    <template v-for="(item, index) in gangPolicyList">
                        <div v-if="index < 5" class="card-item" @click="openDocument(item.filePath)" :key="index">
                            <div class="card-content">{{item.title}}</div>
                            <div class="card-time">{{item.publishTimeStr}}</div>
                        </div>
                    </template>
                </div>
                <div v-else class="list-empty">暂无内容</div>
            </div>
            <div class="card">
                <div class="card-header">
                    <div class="card-title">
                        <img src="../../assets/img/line.png" alt />
                        <span>事项清单</span>
                    </div>
                    <div class="card-more" @click="toPage('pages/gangEasyMake/itemMore')">
                        <span style="margin-right: 3px; color: #0c92ff;">查看更多</span>
                        <u-icon color="#0c92ff" name="arrow-right"></u-icon>
                    </div>
                </div>
                <div v-if="gangItemList.length" class="card-list">
                    <template v-for="(item, index) in gangItemList">
                        <div v-if="index < 5" class="card-item" @click="toDetail(item, itemName, itemCode)" :key="index">
                            <div class="card-content">{{item.title}}</div>
                            <div class="card-time">{{item.publishTimeStr}}</div>
                        </div>
                    </template>
                </div>
                <div v-else class="list-empty">暂无内容</div>
            </div>
            <div class="card">
                <div class="card-header">
                    <div class="card-title">
                        <img src="../../assets/img/line.png" alt />
                        <span>工作动态</span>
                    </div>
                    <div class="card-more" @click="toPage('pages/gangEasyMake/workMore')">
                        <span style="margin-right: 3px; color: #0c92ff;">查看更多</span>
                        <u-icon color="#0c92ff" name="arrow-right"></u-icon>
                    </div>
                </div>
                <div v-if="gangItemList.length" class="card-list">
                    <template v-for="(item, index) in gangWorkList">
                        <div v-if="index < 5" class="card-item" @click="toDetail(item, workName, workCode)" :key="index">
                            <div class="card-content">{{item.title}}</div>
                            <div class="card-time">{{item.publishTimeStr}}</div>
                        </div>
                    </template>
                </div>
                <div v-else class="list-empty">暂无内容</div>
            </div>
    </div>
</template>
<script>
import Empty from "../../components/Empty.vue";
import { getPolicyListAPI } from "../../api/article";
import { getGangListAPI } from "../../api/gang";
export default {
    components: { Empty },
    data() {
        return {
            loading: false,
            gangPolicyList: [],
            gangItemList: [],
            gangWorkList: [],
            policyName: '政策文件',
            itemName: '事项清单',
            workName: '工作动态',
            policyCode: 1, // 政策文件code
            itemCode: 2, // 事项清单code
            workCode: 3, // 工作动态code
        };
    },
    onShareAppMessage() {},
    onShow() {
        this.loading = true;
        wx.showLoading({
            title: "加载中...",
        });
        Promise.all([
            getGangListAPI()
        ]).then((res) => {
            this.gangPolicyList = res[0].data.gangPolicyResps;
            this.gangItemList = res[0].data.gangItemResps;
            this.gangWorkList = res[0].data.gangWorkResps;
            wx.hideLoading();
            this.loading = false;
        });
    },
    methods: {
        openDocument(url) {
            wx.showLoading({
                title: "打开文件中...",
            });
            wx.downloadFile({
                url,
                success: function (res) {
                    const filePath = res.tempFilePath;
                    wx.openDocument({
                        filePath: filePath,
                        success: function (res) {
                            wx.hideLoading();
                        },
                    });
                },
            });
        },
        toPage(url, params) {
            this.$u.route({ url, params });
        },
        toDetail(item, typeName, typeCode) {
            this.toPage("pages/gangEasyMake/detail", {
                id: item.id,
                title: typeName,
                typeCode: typeCode
            });
        },
    },
};
</script>
<style scoped lang="scss">
@import "../../assets/scss/common.scss";

.container {
    min-height: 100vh;
    background-color: #fafafa;
    box-sizing: border-box;
    padding: 15px;
    .grids {
        display: flex;
        flex-direction: column;
        border-radius: 8px;
        background-color: #fff;
        margin-bottom: 15px;
        box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.1) !important;
        .grids-title {
            padding: 15px 15px 8px;
            border-bottom: 1px solid #efefef;
            font-size: 18px;
            font-weight: bold;
        }
        .grids-content {
            display: flex;
            flex-wrap: wrap;
            padding: 15px;
            .grid {
                width: 25%;
                display: flex;
                flex-direction: column;
                align-items: center;
                .icon {
                    width: 50px;
                    height: 50px;
                    margin-bottom: 5px;
                }
                .text {
                    text-align: center;
                    font-size: 13px;
                }
            }
        }
    }
    .card {
        padding: 15px 0;
        border-radius: 8px;
        background-color: #fff;
        margin-bottom: 15px;
        box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.1) !important;
        .card-header {
            padding: 0 15px 8px;
            border-bottom: 1px solid #efefef;
            margin-bottom: 12px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            .card-title {
                font-size: 18px;
                font-weight: bold;
                display: flex;
                align-items: center;
                img {
                    width: 5px;
                    height: 18px;
                    margin-right: 10px;
                }
            }
            .card-more {
                color: $color_regular-text;
                font-size: 12px;
            }
        }
        .card-list {
            padding: 0 15px;
            .card-item {
                border-bottom: 1px solid #efefef;
                padding-bottom: 10px;
                margin-bottom: 10px;
                &:last-child {
                    padding: 0;
                    margin: 0;
                    border: none;
                }
                .card-content {
                    font-size: 15px;
                    line-height: 22px;
                    margin-bottom: 3px;
                    display: -webkit-box;
                    -webkit-box-orient: vertical;
                    -webkit-line-clamp: 1;
                    overflow: hidden;
                    color: #0c92ff;
                }
                .card-time {
                    padding-right: 5px;
                    font-size: 13px;
                    color: $color_secondary-text;
                }
            }
        }
        .list-empty {
            text-align: left;
            padding: 10px 0 10px 20px;
            font-size: 14px;
            color: $color_secondary-text;
        }
        .card-tip {
            padding: 0 15px;
            font-size: 14px;
            line-height: 22px;
        }
    }
}
</style>

